package edu.mama.college.mapper;

import edu.mama.college.model.Course;
import edu.mama.college.model.Lesson;
import edu.mama.college.model.UserCourse;
import edu.mama.college.model.UserStudyRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 课程的MyBatis操作接口
 */
@Mapper
@Repository(value ="CourseMapper")
public interface CourseMapper {

    @Select("SELECT * from course order by students desc limit 0,#{limit}")
    List<Course> getHotCourses(int limit);

    Course getCourseDetail(int courseId);

    List<Course> courseList(int page,int size, String name,String teacher);

    int courseTotal(int page,int size, String name,String teacher);

    @Select("INSERT INTO course (`desc`,`hour`,`name`,poster,teacher) VALUES(#{desc},#{hour},#{name},#{poster},#{teacher})")
    void create(Course course);

    @Select("UPDATE course SET `desc` = #{desc},`hour`=#{hour},`name`=#{name},poster=#{poster},teacher=#{teacher} WHERE id = #{id}")
    void update(Course course);

    @Select("UPDATE course SET deleted = true where id = #{id}")
    void delete(int id);

    void addLessons(List<Lesson> lessonList);

    @Select("UPDATE lesson set name = #{name},type=#{type},resource=#{resource},duration=#{duration} where id = #{id}")
    void updateLesson(Lesson lesson);

    @Select("UPDATE lesson SET deleted = true where id = #{id}")
    void deleteLesson(int id);

    int studentListByCourseCount(int courseId);

    List<UserCourse> studentListByCourse(int page, int size, int courseId);

    @Select("UPDATE course SET students = students +1 where  id = #{courseId}")
    void updateCourseStudents(int courseId);
}
